package day_2022_7_to_8.day48;

import java.util.Stack;

/**
 * @author haomin
 * @date 2022/08/31 18:15
 **/
public class Day46_9_Offer30_MinStack {
    class MinStack {
        Stack<Integer> s1;
        Stack<Integer> s2;
        /** initialize your data structure here. */
        public MinStack() {
            s1 = new Stack<>();
            s2 = new Stack<>();
        }

        public void push(int x) {
            s1.push(x);
            if(s2.isEmpty()) s2.push(x);
            else s2.push(Math.min(x, s2.peek()));
        }

        public void pop() {
            s1.pop();
            s2.pop();
        }

        public int top() {
            return s1.peek();
        }

        public int min() {
            return s2.peek();
        }
    }
}